Skip to content

fix(redirect): fd3 redirection pattern 3>&1 >file now routes correctly#1139

Merged
chaliy merged 1 commit intomainfrom
fix/issue-1115-fd3-redirect
Apr 7, 2026
Merged

fix(redirect): fd3 redirection pattern 3>&1 >file now routes correctly#1139
chaliy merged 1 commit intomainfrom
fix/issue-1115-fd3-redirect

Conversation

@chaliy
Copy link
Copy Markdown
Contributor

@chaliy chaliy commented Apr 7, 2026

Summary

  • Fix { echo msg 1>&3; echo data; } 3>&1 >file pattern where fd3 content ended up in file instead of original stdout
  • Add extra_fds field to ExecResult for carrying fd3+ content through execution layers
  • Generalize apply_redirections_fd_table from hardcoded fd1/fd2 to HashMap-based arbitrary fd support

What

The fd-table redirect model only tracked fd1 (stdout) and fd2 (stderr). When 3>&1 >file was used on a compound command, the 3>&1 dup was silently ignored because fd3 had no slot in the table. Content written to fd3 via inner 1>&3 redirects was lost.

How

  1. Added extra_fds: HashMap<i32, String> to ExecResult — carries content written to fd3+ via inner redirects
  2. In apply_redirections fast path: 1>&N (N>=3) moves stdout to extra_fds[N]
  3. Rewrote apply_redirections_fd_table to use a HashMap<i32, FdTarget> instead of separate fd1/fd2 variables, supporting arbitrary fd numbers
  4. Updated execute_list and execute_command_sequence_impl to accumulate extra_fds from sub-commands

Tests

  • Unit test: test_fd3_redirect_pattern verifying the full 3>&1 >file pattern
  • Spec test: fd3_redirect_pattern in exec-fd-redirect.test.sh

Closes #1115

@chaliy chaliy force-pushed the fix/issue-1115-fd3-redirect branch 5 times, most recently from ef930ba to e00d366 Compare April 7, 2026 05:11
Use interpreter-level pending_fd_output buffer to carry fd3+ content
from inner 1>&N redirects to compound-level fd-table routing.

Changes:
- Interpreter.pending_fd_output: buffer for fd3+ output
- apply_redirections fast path: 1>&N (N>=3) moves stdout to pending buffer
- apply_redirections_fd_table: supports fd3+ via extra_fd_targets + pending
- route_fd_table_content: extracted non-async helper to avoid state machine bloat

Closes #1115
@chaliy chaliy force-pushed the fix/issue-1115-fd3-redirect branch from e00d366 to 215b591 Compare April 7, 2026 05:20
@chaliy chaliy merged commit 35a9f8f into main Apr 7, 2026
27 checks passed
@chaliy chaliy deleted the fix/issue-1115-fd3-redirect branch April 7, 2026 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(redirect): fd3 redirection pattern 3>&1 >file sends fd3 to file instead of original stdout

1 participant